<include file="public/header"/>

<div class="am-cf admin-main">
    <!-- sidebar start -->
    <include file="public/sidebar"/>
    <!-- sidebar end -->

    <!-- content start -->
    <div class="admin-content">
        <div class="am-cf am-padding">
            <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">菜单分配</strong></div>
            <span id="res"> {$name}</span>{$desc}
        </div>

            <input type="checkbox" id="all"/>全选
            <hr/>
            <foreach name="datas" item="data">
                <assign name="first" value="$data.first"/>
                <div>
                    <!--一级菜单div-->
                    <input type="checkbox" name="mids" class="check" value="{$first.mid}"/>
                    {$first.menu}
                    <br/>
                    <!--二级菜单-->
                    <assign name="second" value="$data.second"/>
                    <foreach name="second" item="se">
                        <input type="checkbox" name="mids" class="check" value="{$se.mid}"/>
                        {$se.menu}
                    </foreach>
                    <!--end-->
                    <br/>
                    <!--三级菜单-->
                    <assign name="thirds" value="$data.third"/>
                    <foreach name="thirds" item="thir">
                        <assign name="thi" value="$thir.th"/>
                        <foreach name="thi" item="t">
                            <input type="checkbox" name="mids" class="check" value="{$t.mid}"/>
                            {$t.menu}
                        </foreach>
                    </foreach>

                    <!--end-->
                </div>
                <hr/>
            </foreach>
            <!--角色-->
            <label class="am-u-sm-3 am-form-label">角色</label>
            <select id="ro" name="ro">
                <foreach name="roles" item="role">
                    <option value="{$role.rid}">{$role.rolename}</option>
                </foreach>
            </select>
            <!--end-->
            <div class="am-u-sm-9 am-u-sm-push-3">
                <button type="submit" class="am-btn am-btn-primary" id="submit">提交分配</button>
            </div>
    </div>
    <!-- content end -->
</div>
<script src="__PUBLIC__/assets/js/jquery.min.js"></script>
<script>
    $("#all").click(function () {
        if (this.checked) {
            $(".check").attr("checked", true);
        } else {
            $(".check").attr("checked", false);
        }
    });

    $("#submit").on("click", function () {
        var arr = new Array;
        $("input[name='mids']:checked").each(function () {
            arr.push($(this).val());
        });
        $.post(
                "http://http://f.mantou58.com/index.php/Basic/perPost",
//                {"mids": arr},
                {"role": $("#ro").val()},
                function (data) {
                    if (data.status == 1) {
                        alert(data.status);
                        alert("1");
                    } else {
                        alert(data.status);
                        alert("2");
                    }
                }
        )
    });
</script>
<include file="public/footer"/>
